home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / devices / msh_1_5 / part01 / src / han.h < prev    next >
C/C++ Source or Header  |  1990-02-21  |  9KB  |  294 lines

  1. /*-
  2.  *  $Id: han.h,v 1.4 90/01/27 20:33:22 Rhialto Exp $
  3.  *
  4.  *  The header file for the MESSYDOS: file system handler
  5.  *
  6. -*/
  7.  
  8. #include "dev.h"
  9.  
  10. #define MODE_READWRITE    1004L
  11. #define MODE_CREATEFILE (1L<<31)
  12. #define FILE_DIR    1
  13. #define FILE_FILE   -1
  14.  
  15.  
  16. /* #define MS_BPS      512    /* Bytes per sector */
  17. #define MS_SPC        2        /* Sectors per cluster */
  18. #define MS_RES        1        /* Reserved sectors (boot block) */
  19. #define MS_NFATS    2        /* Number of FATs */
  20. #define MS_NDIRS    112     /* Number of directory entries */
  21. #define MS_NSECTS   1440    /* total number of sectors */
  22. #define MS_SPF        3        /* Sectors per FAT */
  23. /* #define MS_SPT      9    /* Sectors per track */
  24. /* #define MS_SPT_MAX  9    /* Max sectors per track */
  25. /* #define MS_NSIDES   2    /* Tracks per cylinder */
  26. #define MS_ROOTDIR  (MS_RES + MS_SPF * MS_NFATS)
  27. #define MS_DIRENTSIZE  sizeof(struct MsDirEntry) /* size of a directory entry */
  28.  
  29. #define MS_FIRSTCLUST    2    /* Very strange convention... */
  30.  
  31. #define FAT_EOF     0xFFFF    /* end of file FAT entry */
  32. #define FAT_UNUSED  0        /* unused block */
  33. #define SEC_EOF     -1        /* end of FAT chain */
  34.  
  35. #define DIR_DELETED        0xE5
  36. #define DIR_DELETED_MASK    0x80
  37.  
  38. /*
  39.  * This structure has its byte order wrong, when it is on the disk.
  40.  */
  41.  
  42. struct MsDirEntry {
  43.     byte        msd_Name[8];
  44.     byte        msd_Ext[3];
  45.     byte        msd_Attributes;
  46.     byte        msd_Pad1[10];
  47.     word        msd_Time;    /* in 2s of seconds since begin of the day */
  48.     word        msd_Date;
  49.     word        msd_Cluster;
  50.     ulong        msd_Filesize;
  51. };
  52.  
  53. #define ATTR_READONLY        0x01
  54. #define ATTR_HIDDEN        0x02
  55. #define ATTR_SYSTEM        0x04
  56. #define ATTR_VOLUMELABEL    0x08
  57. #define ATTR_DIRECTORY        0x10
  58. #define ATTR_ARCHIVED        0x20
  59.  
  60. #define ATTR_DIR        (ATTR_DIRECTORY | ATTR_VOLUMELABEL)
  61.  
  62. #define DATE_MIN        0x21
  63.  
  64. struct DirEntry {
  65.     struct MsDirEntry de_Msd;
  66.     word        de_Sector;
  67.     word        de_Offset;
  68. };
  69.  
  70. struct DiskParam {
  71.     word        bps;    /* bytes per sector. max MS_BPS supported */
  72.     byte        spc;    /* sectors per cluster */
  73.     word        res;    /* reserved sectors (boot block) */
  74.     byte        nfats;    /* number of fats */
  75.     word        ndirs;    /* number of directory entries */
  76.     word        nsects;    /* total number of sectors on disk */
  77.     byte        media;    /* media byte */
  78.     word        spf;    /* sectors per fat */
  79.     word        spt;    /* sectors per track. Only MS_SPT
  80.                  * supported */
  81.     word        nsides;    /* # sides. Max MS_NSIDES supported */
  82.     word        nhid;    /* Number of hidden sectors */
  83.     /* derived parameters */
  84.     word        start;    /* sector of cluster 0 */
  85.     word        maxclst;    /* highest cluster number */
  86.     word        rootdir;    /* first sector of root dir */
  87.     word        ndirsects;    /* # of root directory sectors */
  88.     word        datablock;    /* first block available for files &c */
  89.     word        bpc;    /* bytes per cluster */
  90.     word        nsectsfree; /* amount of free space */
  91.     long        lowcyl;    /* offset to lowcyl */
  92.     struct DirEntry vollabel;    /* copy of volume label */
  93.     word        fat16bits;    /* Is the FAT 16 bits/entry? */
  94. };
  95.  
  96. /*
  97.  * A pointer to an MSFileLock is put into the fl_Key field of a DOS
  98.  * FileLock structure. We share the MSFileLock with all FileLocks on the
  99.  * same file. This way, you can compare FileLocks based on their fl_Key
  100.  * and fl_Task fields, as seems to be done sometimes. Also, a pointer to
  101.  * an MSFileLock is put in MSFileHandles.
  102.  *
  103.  * For ease, we keep a copy of the directory entry in core, WITH THE BYTE
  104.  * ORDER CORRECTED FOR THIS PROCESSOR.
  105.  */
  106.  
  107. struct MSFileLock {
  108.     struct MinNode  msfl_Node;
  109.     short        msfl_Refcount;    /* -1: exclusive, >0: # of shared
  110.                      * locks */
  111.     struct MSFileLock *msfl_Parent;    /* Pointer to parent directory */
  112.     struct MsDirEntry msfl_Msd; /* Copy of directory entry */
  113.     word        msfl_DirSector;    /* Location of directory entry */
  114.     word        msfl_DirOffset;
  115. };
  116.  
  117. /*
  118.  * A pointer to an MSFileHandle is put into the fh_Arg1 field of a DOS
  119.  * FileHandle. We get that value with many DOS packets that manipulate the
  120.  * contents of a file.
  121.  */
  122.  
  123. struct MSFileHandle {
  124.     struct MSFileLock *msfh_FileLock;
  125.     long        msfh_SeekPos;
  126.     word        msfh_Cluster;
  127. };
  128.  
  129. /*
  130.  * Return values of CompareNames.
  131.  */
  132.  
  133. #define CMP_NOT_EQUAL        0    /* Names do not match at all */
  134. #define CMP_OK_DIR        1    /* Name matches with a subdir entry */
  135. #define CMP_OK_FILE        2    /* Name matches with a file entry */
  136. #define CMP_INVALID        3    /* First part of name matches with a file
  137.                  * entry, or other invalid component name */
  138. #define CMP_FREE_SLOT        5
  139. #define CMP_END_OF_DIR        6
  140.  
  141. struct LockList {
  142.     struct MinList  ll_List;
  143.     void       *ll_Cookie;    /* we don't want to know what this is! */
  144. };
  145.  
  146. struct CacheSec {
  147.     struct MinNode  sec_Node;
  148.     word        sec_Number;
  149.     word        sec_Refcount;
  150.     byte        sec_Data[2];/* Really Disk.bps */
  151. };
  152.  
  153. #define SEC_DIRTY   0x8000    /* Bit in sec_Refcount */
  154.  
  155. #define OFFSETOF(tag, member)   ((long)(&((struct tag *)0)->member))
  156.  
  157. #define     DELAY_OFF        0    /* Motor is off */
  158. #define     DELAY_RUNNING1  1    /* Motor may be on */
  159. #define     DELAY_RUNNING2  2    /* Motor may be on */
  160. #define     DELAY_RUNNING   3    /* Running1 | 2 */
  161. #define     DELAY_DIRTY     4    /* We have dirty buffers to flush */
  162.  
  163.  
  164. extern long    Wait();
  165. extern struct MsgPort *CreatePort();
  166. extern struct IOExtTD *CreateExtIO();
  167. extern void    *AllocMem(), FreeMem();
  168. extern byte    *index(), *rindex();
  169. extern void    *CheckIO();
  170.  
  171. /*
  172.  * PACK.C
  173.  */
  174. extern char *DevName;
  175. extern long UnitNr;
  176. extern ulong DevFlags;
  177.  
  178. /*
  179.  * HANMAIN.C
  180.  */
  181. extern byte    ToUpper();
  182. extern long    lmin();
  183. extern byte    *ZapSpaces();
  184. extern byte    *ToMSName();
  185. extern long    MSDiskInfo();
  186. extern void    MSDiskInserted();
  187. extern int    MSDiskRemoved();
  188. extern void    HanCloseDown();
  189. extern int    HanOpenUp();
  190.  
  191. /*
  192.  * HANSEC.C
  193.  */
  194. extern struct MsgPort *DiskReplyPort;
  195. extern struct IOExtTD *DiskIOReq;
  196. extern struct IOStdReq *DiskChangeReq;
  197. extern struct DiskParam Disk;
  198. extern byte    *Fat;
  199. extern short    FatDirty;    /* Fat must be written to disk */
  200. extern short    error;        /* To put the error value; for Result2 */
  201. extern long    IDDiskState;    /* InfoData.id_DiskState */
  202. extern long    IDDiskType;    /* InfoData.id_DiskType */
  203. extern struct timerequest *TimeIOReq;    /* For motor-off delay */
  204. extern struct MinList CacheList;/* Sector cache */
  205. extern int    CurrentCache;    /* How many cached buffers do we have */
  206. extern int    MaxCache;    /* Maximum amount of cached buffers */
  207. extern ulong    BufMemType;
  208. extern long    CacheBlockSize; /* Size of disk block + overhead */
  209. extern int    DelayState;
  210. extern byte    *Word8086;
  211. extern word    Get8086Word();
  212. extern word    OtherEndianWord();
  213. extern ulong    OtherEndianLong();
  214. extern void    OtherEndianMsd();
  215. extern word    ClusterToSector();
  216. extern word    ClusterOffsetToSector();
  217. extern word    DirClusterToSector();
  218. extern word    SectorToCluster();
  219. extern word    NextCluster();
  220. extern word    NextClusteredSector();
  221. extern word    FindFreeSector();
  222. extern struct CacheSec *FindSecByNumber();
  223. extern struct CacheSec *FindSecByBuffer();
  224. extern struct CacheSec *NewCacheSector();
  225. extern void    FreeCacheSector();
  226. extern void    InitCacheList();
  227. extern void    FreeCacheList();
  228. extern void    MSUpdate();
  229. extern void    StartTimer();
  230. extern byte    *GetSec();
  231. extern byte    *EmptySec();
  232. extern void    PutSec();
  233. extern void    FreeSec();
  234. extern void    MarkSecDirty();
  235. extern void    WriteFat();
  236. extern int    ReadBootBlock();
  237. extern int    IdentifyDisk();
  238. extern int    TDMotorOff();
  239. extern int    TDGetNumCyls();
  240.  
  241. /*
  242.  * HANLOCK.C
  243.  */
  244. extern struct LockList *LockList;    /* List of all locked files we
  245.                      * have. Note this is not the same
  246.                      * as all locks we have */
  247. extern struct MSFileLock *RootLock;    /* Lock on root directory */
  248. extern struct MSFileLock *EmptyFileLock;    /* 2nd result of MSLock() */
  249.  
  250. extern struct DirEntry FakeRootDirEntry;
  251. extern int    CompareNames();
  252. extern void    NextDirEntry();
  253. extern struct DirEntry *FindNext();
  254. extern struct MSFileLock *MakeLock();
  255. extern void    WriteLock();
  256. extern void    PrintDirEntry();
  257. extern struct MSFileLock *MSLock();
  258. extern struct MSFileLock *MSDupLock();
  259. extern struct MSFileLock *MSParentDir();
  260. extern int    MSUnLock();
  261. extern void    ExamineDirEntry();
  262. extern int    MSExamine();
  263. extern int    MSExNext();
  264. extern long    MSSetProtect();
  265. extern void    WriteFileLock();
  266. extern void    UpdateFileLock();
  267. extern struct LockList *NewLockList();
  268. extern void    FreeLockList();
  269.  
  270. /*
  271.  * HANFILE.C
  272.  */
  273. extern int    GetFat();
  274. extern void    FreeFat();
  275. extern word    GetFatEntry();
  276. extern void    SetFatEntry();
  277. extern word    FindFreeCluster();
  278. extern word    ExtendClusterChain();
  279. extern void    FreeClusterChain();
  280. extern struct MSFileHandle *MSOpen();
  281. extern void    MSClose();
  282. extern long    MSSeek();
  283. extern long    MSRead();
  284. extern long    MSWrite();
  285. extern long    MSDeleteFile();
  286. extern long    MSSetDate();
  287. extern struct MSFileLock *MSCreateDir();
  288.  
  289. /*
  290.  * DATE.C
  291.  */
  292. extern void    ToDateStamp();
  293. extern void    ToMSDate();
  294.